package com.zycfc.zsf.boot.logback.core;

import java.io.*;
import com.zycfc.zsf.boot.util.text.*;
import com.zycfc.zsf.boot.common.context.*;
import com.zycfc.zsf.boot.util.net.*;
import com.zycfc.zsf.boot.util.time.*;
import java.util.*;
import org.slf4j.*;

public class RuleTranBuilder implements Serializable
{
    private static final Logger log;
    private static final long serialVersionUID = 1L;
    private String flowId;
    private String bizId;
    private String tranCd;
    private String idNo;
    private String name;
    private String channelNo;
    private String ip;
    private String sendTime;
    private String receiveTime;
    private String requestData;
    private String responseData;
    private String exeSts;
    private String respCode;
    private String grayscaleFlag;
    
    public RuleTranBuilder() {
        this.exeSts = "S";
    }
    
    public RuleTranBuilder setFlowId(final String flowId) {
        this.flowId = flowId;
        return this;
    }
    
    public RuleTranBuilder setBizId(final String bizId) {
        this.bizId = bizId;
        return this;
    }
    
    public RuleTranBuilder setTranCd(final String tranCd) {
        this.tranCd = tranCd;
        return this;
    }
    
    public RuleTranBuilder setIdNo(final String idNo) {
        this.idNo = idNo;
        return this;
    }
    
    public RuleTranBuilder setName(final String name) {
        this.name = name;
        return this;
    }
    
    public RuleTranBuilder setChannelNo(final String channelNo) {
        this.channelNo = channelNo;
        return this;
    }
    
    public RuleTranBuilder setSendTime(final String sendTime) {
        this.sendTime = sendTime;
        return this;
    }
    
    public RuleTranBuilder setReceiveTime(final String receiveTime) {
        this.receiveTime = receiveTime;
        return this;
    }
    
    public RuleTranBuilder setRequestData(final String requestData) {
        this.requestData = requestData;
        return this;
    }
    
    public RuleTranBuilder setResponseData(final String responseData) {
        this.responseData = responseData;
        return this;
    }
    
    public RuleTranBuilder setExeSts(final String exeSts) {
        this.exeSts = exeSts;
        return this;
    }
    
    public RuleTranBuilder setExeStsSucc() {
        this.exeSts = "S";
        this.respCode = "0000000";
        return this;
    }
    
    public RuleTranBuilder setExeStsFail() {
        this.exeSts = "F";
        return this;
    }
    
    public RuleTranBuilder setExeStsFail(final String excpetionMsg) {
        this.exeSts = "F";
        if (StringUtils.isAllBlank(new CharSequence[] { excpetionMsg })) {
            this.respCode = "Z999999";
        }
        final String[] array = excpetionMsg.split("##@##");
        if (array.length == 1) {
            final String msg = array[0];
            final int end = Math.min(msg.length(), 20);
            this.respCode = msg.substring(0, end);
        }
        else if (array.length >= 2) {
            this.respCode = array[0];
        }
        return this;
    }
    
    public RuleTranBuilder setRespCode(final String respCode) {
        this.respCode = respCode;
        return this;
    }
    
    private void dealGrayscale() {
        try {
            final String key = ZsfRootContext.get("grayscaleFlag");
            if ("true".equals(key)) {
                this.grayscaleFlag = "1";
            }
            else {
                this.grayscaleFlag = "0";
            }
            if (StringUtils.isNotEmpty(key)) {
                ZsfRootContext.remove("grayscaleFlag");
            }
        }
        catch (Exception e) {
            RuleTranBuilder.log.error("dealGrayscale-Exception:", (Throwable)e);
        }
    }
    
    public RuleTranInf build() {
        this.ip = NetUtils.getLocalHost();
        if (StringUtils.isBlank((CharSequence)this.sendTime)) {
            this.sendTime = DateUtils.DEFAULT_FORMAT.format(new Date());
        }
        if (StringUtils.isBlank((CharSequence)this.receiveTime)) {
            this.receiveTime = DateUtils.DEFAULT_FORMAT.format(new Date());
        }
        if ("F".equals(this.exeSts) && StringUtils.isEmptyAll(this.respCode)) {
            this.respCode = "Z999999";
        }
        else if ("S".equals(this.exeSts) && StringUtils.isEmptyAll(this.respCode)) {
            this.respCode = "0000000";
        }
        this.dealGrayscale();
        return new RuleTranInf(this);
    }
    
    public String getFlowId() {
        return this.flowId;
    }
    
    public String getBizId() {
        return this.bizId;
    }
    
    public String getTranCd() {
        return this.tranCd;
    }
    
    public String getIdNo() {
        return this.idNo;
    }
    
    public String getName() {
        return this.name;
    }
    
    public String getChannelNo() {
        return this.channelNo;
    }
    
    public String getIp() {
        return this.ip;
    }
    
    public String getSendTime() {
        return this.sendTime;
    }
    
    public String getReceiveTime() {
        return this.receiveTime;
    }
    
    public String getRequestData() {
        return this.requestData;
    }
    
    public String getResponseData() {
        return this.responseData;
    }
    
    public String getExeSts() {
        return this.exeSts;
    }
    
    public String getRespCode() {
        return this.respCode;
    }
    
    public String getGrayscaleFlag() {
        return this.grayscaleFlag;
    }
    
    static {
        log = LoggerFactory.getLogger((Class)RuleTranBuilder.class);
    }
}
